﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div id="searchDiv" class="col-sm-12 search-collapse">
                                <div class="select-list">
                                    <ul>
                                        <li>
                                            从<input id="date" col="Date" type="text" />
                                        </li>
                                        <li>
                                            到<input id="enddate" col="EndDate" type="text" />
                                        </li>
                                        <li>
                                            服务项目：<span id="productId" col="ProductId"></span>
                                        </li>
                                        <li>
                                            <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                        </li>
                                    </ul>
                                    <ul>
                                        <li>
                                            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm()"><i class="fa fa-plus"></i> 新增</a>
                                        </li>
                                        <li>
                                            <a id="btnCopy" class="btn btn-primary" onclick="showCopyForm()"><i class="fa fa-edit"></i> 复制</a>
                                        </li>
                                        <li>
                                            <a id="btnDelete" class="btn btn-danger" onclick="showDelForm()"><i class="fa fa-remove"></i> 撤销</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>人员日程安排</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12" style="font-size:14px">
                                <div class="col-sm-12 select-table table-striped">
                                    <table id="userGridTable" data-mobile-responsive="true"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>设备日程安排</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12" style="font-size:14px">
                                <div class="col-sm-12 select-table table-striped">
                                    <table id="deviceGridTable" data-mobile-responsive="true"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>日程安排</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12" style="font-size:14px">
                                <div class="col-sm-12 select-table table-striped">
                                    <table id="scheduleGridTable" data-mobile-responsive="true"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
    $(function () {
        initGrid();
        $(".modal").appendTo("body"), $("[data-toggle=popover]").popover(), $(".collapse-link").click(function () {
            var div_ibox = $(this).closest("div.ibox"),
                e = $(this).find("i"),
                i = div_ibox.find("div.ibox-content");
            i.slideToggle(200),
                e.toggleClass("fa-chevron-up").toggleClass("fa-chevron-down"),
                div_ibox.toggleClass("").toggleClass("border-bottom"),
                setTimeout(function () {
                    div_ibox.resize();
                }, 50);
        });
    });

        function initGrid() {
            var d = new Date();
            var ed = new Date();
            ed.setDate(d.getDate() + 6);
            laydate.render({ elem: '#date', value: d });
            laydate.render({ elem: '#enddate', value: ed });

            $("#productId").ysComboBox({
                url: '@Url.Content("~/ProductManage/Product/GetListJson")',
                key: "Id",
                value: "ProductName",
                multiple: true
            });
            GetColumns();
            $('#deviceGridTable').ysTable({
                pageSize: 1000,
                queryParams: function (params) {
                    var pagination = $('#deviceGridTable').ysTable('getPagination', params);
                    var queryString = $('#searchDiv').getWebControls(pagination);
                    return queryString;
                },
                onClickCell: function (field, value, row, td, column) {
                    if (value > 0) {
                        var deviceNo = row.DeviceNo,
                            date = column.title;
                        ys.openDialog({
                            title: '日程详情',
                            width: '900px',
                            height: '550px',
                            content: '@Url.Content("~/ScheduleManage/Schedule/ScheduleDetail")' + '?date=' + date + '&deviceno=' + deviceNo,
                        });
                    }
                }
            });

            $('#userGridTable').ysTable({
                pageSize: 1000,
                queryParams: function (params) {
                    var pagination = $('#userGridTable').ysTable('getPagination', params);
                    var queryString = $('#searchDiv').getWebControls(pagination);
                    return queryString;
                },
                onClickCell: function (field, value, row, td, column) {
                    if (value > 0) {
                        var userid = row.UserId,
                            date = column.title;
                        ys.openDialog({
                            title: '日程详情',
                            width: '900px',
                            height: '550px',
                            content: '@Url.Content("~/ScheduleManage/Schedule/ScheduleDetail")' + '?date=' + date + '&userid=' + userid,
                        });
                    }
                }
            });

            $('#scheduleGridTable').ysTable({
                pageSize: 1000,
                queryParams: function (params) {
                    var pagination = $('#scheduleGridTable').ysTable('getPagination', params);
                    var queryString = $('#searchDiv').getWebControls(pagination);
                    return queryString;
                }
            });
        }

        function searchGrid() {
            GetColumns();
        }

        function GetColumns() {
            var date = $("#date").val();
            var enddate = $("#enddate").val();
            ys.ajax({
                url: '@Url.Content("~/SystemManage/Days/GetListJson")' + '?date=' + date + '&enddate=' + enddate,
                type: 'get',
                success: function (obj) {
                    if (obj.Result) {
                        var deviceGridColumns = [
                            { field: 'DeviceName', title: '设备' },
                            { field: 'DeviceNo', title: '编号' }
                        ];
                        var userGridColumns = [
                            { field: 'UserId', title: 'UserId', visible: false },
                            { field: 'UserName', title: '人员' }
                        ];
                        var scheduleGridColumns = [
                            { field: 'No', title: 'No', visible: false },
                            { field: 'Name', title: 'Name', visible: false }
                        ];
                        for (var o in obj.Result) {
                            var columns = {};
                            columns.field = obj.Result[o].CDay;
                            columns.title = new Date(obj.Result[o].Date).toLocaleDateString();
                            columns.formatter = function (value, row, index) {
                                if (value == 0 || !value) {
                                    return '<span class="badge badge-primary">&nbsp</span>';
                                } else if (value == 1) {
                                    return '<span class="badge badge-warning" style="cursor: pointer;">' + value + '</span>';
                                } else {
                                    return '<span class="badge badge-danger" style="cursor: pointer;">' + value + '</span>';
                                }
                            };
                            deviceGridColumns.push(columns);
                            userGridColumns.push(columns);
                        }
                        for (var o in obj.Result) {
                            var columns = {};
                            columns.field = obj.Result[o].CDay;
                            columns.title = new Date(obj.Result[o].Date).toLocaleDateString();
                            columns.formatter = function (value, row, index) {
                                if (value < 1) {
                                    return '<span>' + row.Name + '</span>';
                                } else {
                                    return '<span class="badge badge-success">' + row.Name + '</span>';
                                }
                            };
                            scheduleGridColumns.push(columns);
                        }
                        $('#deviceGridTable').bootstrapTable('refreshOptions', {
                            url: '@Url.Content("~/ScheduleManage/Schedule/GetListJson")',
                            columns: deviceGridColumns,
                        });
                        $('#userGridTable').bootstrapTable('refreshOptions', {
                            url: '@Url.Content("~/ScheduleManage/ScheduleUser/GetListJson")',
                            columns: userGridColumns,
                        });
                        $('#scheduleGridTable').bootstrapTable('refreshOptions', {
                            url: '@Url.Content("~/ScheduleManage/Schedule/GetAllListJson")',
                            columns: scheduleGridColumns,
                        });
                    }
                }
            });
        }

        function showSaveForm() {
            ys.openDialog({
                title: '添加日程',
                content: '@Url.Content("~/ScheduleManage/Schedule/ScheduleForm")',
                width: '768px',
                height: '550px',
                callback: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.saveForm(index);
                }
            });
        }

        function showDelForm() {
            ys.openDialog({
                title: '删除日程',
                content: '@Url.Content("~/ScheduleManage/Schedule/ScheduleDelForm")',
                width: '768px',
                height: '550px',
                callback: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.saveForm(index);
                }
            });
        }

        function showCopyForm() {
            ys.openDialog({
                title: '复制日程',
                content: '@Url.Content("~/ScheduleManage/Schedule/ScheduleCopyForm")',
                width: '768px',
                height: '550px',
                callback: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.saveForm(index);
                }
            });
        }
    </script>
